﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using cframework;

public class GUI2 : MonoBehaviour {

	public string testAddString;
	public string testAddString2;
	public string testAddString3;

	public Shooter shooter;
	public GoalArea goalArea;
	
	public Text textScore;
	public Text textShotPower;
	public Text textDirection;
	public Text textTime;
	public GameObject finishUI;

	int time = 60;

	int tempScore = 0;
	float tempShotPower = 0.0f;
	Vector3 tempShotDir = Vector3.zero;

    private void Awake()
    {
		Debug.Log("test add string: " + testAddString);
		Debug.Log("test add string2: " + testAddString2);
		Debug.Log("test add string3: " + testAddString3);
		
        finishUI.SetActive(false);
		StartCoroutine(TimeRun());
    }

	IEnumerator TimeRun()
	{
		while (time > 0)
		{
			textTime.text = time.ToString();
			yield return new WaitForSeconds(1);
			time--;
		}

		finishUI.SetActive(true);
	}

    // Update is called once per frame
    void Update () {
	
		// Score
		if (tempScore != goalArea.score) {
			tempScore = goalArea.score;
			textScore.text = tempScore.ToString();
		}


		// Shot Power
		if (tempShotPower != shooter.shotPower) {
			tempShotPower = shooter.shotPower;
			textShotPower.text = tempShotPower.ToString("0.000");
		}

		// Shot Direction
		if (tempShotDir != shooter.direction) {
			tempShotDir = shooter.direction;
			Quaternion q = Quaternion.Euler(-shooter.transform.eulerAngles);
			Vector4 org = new Vector4(tempShotDir.x, tempShotDir.y, tempShotDir.z, 1);
			Vector4 v = q * org;
			v.Normalize();
			textDirection.text = v.x.ToString("0.00") + ", " + v.y.ToString("0.00") + ", " + v.z.ToString("0.00");
		}
	}



	public void PushedResetButton () {
		StartCoroutine(StartGame.LoadSceneAsync("Assets/BasketballShooting/SampleScene.unity"));
    }
}
